import Demo from '@view/demo';
import Index from '@view/index';
import List from '@view/list';
import VirtualScroll from '@/view/virtualScroll';
import RealScroll from '@/view/realScroll';
import GptIndex from '@/view/gpt'
import _ from 'lodash';

import {
    AppstoreOutlined,
    BarChartOutlined,
    CloudOutlined,
    ShopOutlined,
    TeamOutlined,
    UploadOutlined,
    UserOutlined,
    VideoCameraOutlined,
} from '@ant-design/icons';

export type pathItem = {
    name: string;
    path: string;
    Icon: any;
    WrapComponent: any;
    children?: pathItem;
};

const translateTreeToList = (tree: any[]) => {
    if (!Array.isArray(tree)) {
        return tree;
    }
    let result: any[] = [];
    tree.forEach((item: any) => {
        const { children } = item;
        if (Array.isArray(children)) {
            const list = translateTreeToList(children);
            result = result.concat(list);
            delete item.children;
        }
        result.push(item);
    });
    return result;
}

// 主要维护这个
const pathList: pathItem[] | any[] = [
    {
        name: 'home',
        path: '/home',
        Icon: VideoCameraOutlined,
        // 用于标注组件
        // WrapComponent: Index,
        children: [
            {
                name: 'list',
                path: '/home/list',
                Icon: UploadOutlined,
                WrapComponent: List,
            },
            {
                path: '/home/welcome',
                name: 'welcome',
                Icon: ShopOutlined,
                WrapComponent: Index,
            }
        ]
    },
    {
        name: 'demo',
        path: '/about',
        Icon: BarChartOutlined,
        WrapComponent: Demo,
    },
    {
        name: 'virtualScroll',
        path: '/virtualScroll',
        Icon: TeamOutlined,
        WrapComponent: VirtualScroll,
    },
    {
        name: 'realScroll',
        path: '/realScroll',
        Icon: TeamOutlined,
        WrapComponent: RealScroll,
    },
    {
        name: 'gpt',
        path: '/gpt',
        Icon: CloudOutlined,
        WrapComponent: GptIndex
    }
];

const pathFlatList = translateTreeToList(_.cloneDeep(pathList));

export default {
    routeList: pathList,
    pathFlatList,
};
